//
//  FunTuiSuanTableViewCell.m
//  心水宝典
//
//  Created by zr on 2018/8/29.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "FunTuiSuanTableViewCell.h"

@interface FunTuiSuanTableViewCell ()

@property (nonatomic, weak)UIImageView * leftImageView;
@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, strong)UIButton * seeButton;
@property (nonatomic, strong)UIButton * commitButton;
@property (nonatomic, weak)UIView * lineView;

@end

@implementation FunTuiSuanTableViewCell


- (void)setModel:(FunModel *)model{
    
    _model = model;
    
    NSURL * url = [NSURL URLWithString:model.img];
    [self.leftImageView sd_setImageWithURL:url];
    
    self.titleLabel.text = model.title;
    [self.seeButton setTitle:model.hits forState:UIControlStateNormal];
    [self.commitButton setTitle:model.comment forState:UIControlStateNormal];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView * leftImageView = [UIImageView new];
    
    leftImageView.backgroundColor = [UIColor lightGrayColor];
    
    self.leftImageView = leftImageView;
    
    [self.contentView addSubview:self.leftImageView];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    titleLabel.text = @"神奇测试：未来三个月，谁是你 的幸运天使。";
    titleLabel.numberOfLines = 2;
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];
    
    self.seeButton = [self setupButtonWithTitle:@"  2034" WithType:@"see"];
    [self.contentView addSubview:self.seeButton];
    self.commitButton = [self setupButtonWithTitle:@"  2034" WithType:@"commit"];
    [self.contentView addSubview:self.commitButton];
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    self.lineView = lineView;
    
    [self.contentView addSubview:self.lineView];
}

- (void)layoutSubviews{
    
    [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(100 * SCREENH6);
        make.height.mas_equalTo(65 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.leftImageView);
        make.leading.mas_equalTo(self.leftImageView.mas_trailing).offset(5 * SCREENH6);
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
    }];
    
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
        make.bottom.mas_equalTo(self.leftImageView);
    }];
    
    [self.seeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.commitButton.mas_leading).offset(-10 * SCREENH6);
        make.centerY.mas_equalTo(self.commitButton);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1 * SCREENH6);
        make.bottom.mas_equalTo(self.contentView);
    }];
}



- (UIButton *)setupButtonWithTitle:(NSString *)title WithType:(NSString *)type{
    
    UIButton * button = [UIButton new];
    
    NSString * image;
    if ([type isEqualToString:@"see"]) {
        
        image = @"liulanliang";
    }else{
        
        image = @"pinglun";
    }
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setImage:ImageNamed(image) forState:UIControlStateNormal];
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    return button;
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
